<template>
  <div class="system-logs">
    <el-card class="main-card">
      <template #header>
        <div class="card-header">
          <div class="header-left">
            <el-icon class="header-icon"><Document /></el-icon>
            <span class="header-title">管理员操作日志</span>
          </div>
          <div class="header-right">
            <el-button type="success" :icon="Download" @click="exportLogs">
              导出日志
            </el-button>
            <el-button type="primary" :icon="Refresh" @click="refreshLogs">
              刷新
            </el-button>
          </div>
        </div>
      </template>

      <!-- 搜索栏 -->
      <el-form :inline="true" :model="searchForm" class="search-form">
        <el-form-item label="管理员">
          <el-input
            v-model="searchForm.operator"
            placeholder="请输入管理员账号"
            :prefix-icon="User"
            clearable
          />
        </el-form-item>
        <el-form-item label="操作类型">
          <el-select
            v-model="searchForm.operationType"
            placeholder="请选择操作类型"
            clearable
          >
            <el-option label="登录" value="login" />
            <el-option label="新增" value="create" />
            <el-option label="修改" value="update" />
            <el-option label="删除" value="delete" />
            <el-option label="导出" value="export" />
            <el-option label="配置" value="config" />
            <el-option label="其他" value="other" />
          </el-select>
        </el-form-item>
        <el-form-item label="操作状态">
          <el-select
            v-model="searchForm.status"
            placeholder="请选择操作状态"
            clearable
          >
            <el-option label="成功" value="success" />
            <el-option label="失败" value="fail" />
          </el-select>
        </el-form-item>
        <el-form-item label="操作时间">
          <el-date-picker
            v-model="searchForm.dateRange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :shortcuts="dateShortcuts"
            value-format="YYYY-MM-DD"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :icon="Search" @click="handleSearch">
            搜索
          </el-button>
          <el-button :icon="Delete" @click="resetSearch">重置</el-button>
        </el-form-item>
      </el-form>

      <!-- 统计信息 -->
      <div class="statistics-panel">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-card shadow="hover" class="statistics-card">
              <template #header>
                <div class="statistics-header">
                  <span>总日志数</span>
                  <el-icon class="statistics-icon"><DataLine /></el-icon>
                </div>
              </template>
              <div class="statistics-value">{{ statistics.total }}</div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card shadow="hover" class="statistics-card success">
              <template #header>
                <div class="statistics-header">
                  <span>成功操作</span>
                  <el-icon class="statistics-icon"><SuccessFilled /></el-icon>
                </div>
              </template>
              <div class="statistics-value">{{ statistics.success }}</div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card shadow="hover" class="statistics-card warning">
              <template #header>
                <div class="statistics-header">
                  <span>今日操作</span>
                  <el-icon class="statistics-icon"><Calendar /></el-icon>
                </div>
              </template>
              <div class="statistics-value">{{ statistics.today }}</div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card shadow="hover" class="statistics-card danger">
              <template #header>
                <div class="statistics-header">
                  <span>异常操作</span>
                  <el-icon class="statistics-icon"><Warning /></el-icon>
                </div>
              </template>
              <div class="statistics-value">{{ statistics.error }}</div>
            </el-card>
          </el-col>
        </el-row>
      </div>

      <!-- 日志列表 -->
      <el-table
        v-loading="loading"
        :data="logsList"
        style="width: 100%"
        border
        stripe
        highlight-current-row
        @row-click="viewDetail"
      >
        <template #empty>
          <div class="empty-state">
            <el-empty 
              description="暂无日志数据" 
              :image-size="200"
            >
              <div class="empty-text">还没有任何管理员操作日志</div>
              <div class="empty-subtext">管理员操作将会自动记录在此</div>
              <el-button type="primary" :icon="Refresh" @click="refreshLogs" class="mt-4">刷新</el-button>
            </el-empty>
          </div>
        </template>
        <el-table-column prop="id" label="日志ID" width="80" />
        <el-table-column prop="operator" label="管理员" width="120">
          <template #default="{ row }">
            <div class="operator-cell">
              <el-avatar :size="24" :src="row.avatar" />
              <span>{{ row.operator }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="operationType" label="操作类型" width="100">
          <template #default="{ row }">
            <el-tag
              :type="getOperationTypeTag(row.operationType)"
              effect="dark"
            >
              {{ getOperationTypeLabel(row.operationType) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="module" label="操作模块" width="120" />
        <el-table-column
          prop="description"
          label="操作描述"
          min-width="200"
          show-overflow-tooltip
        />
        <el-table-column prop="ip" label="IP地址" width="120">
          <template #default="{ row }">
            <el-tooltip :content="row.location || '未知位置'" placement="top">
              <span>{{ row.ip }}</span>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column prop="operationTime" label="操作时间" width="160">
          <template #default="{ row }">
            <div class="time-cell">
              <div>{{ formatDate(row.operationTime, "YYYY-MM-DD") }}</div>
              <div class="time-detail">
                {{ formatDate(row.operationTime, "HH:mm:ss") }}
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态" width="100">
          <template #default="{ row }">
            <el-tag
              :type="row.status === 'success' ? 'success' : 'danger'"
              effect="dark"
              size="small"
            >
              {{ row.status === "success" ? "成功" : "失败" }}
            </el-tag>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="pagination-container">
        <el-pagination
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>

    <!-- 详情对话框 -->
    <el-dialog
      v-model="detailDialogVisible"
      title="管理员操作日志详情"
      width="800px"
      destroy-on-close
    >
      <el-descriptions :column="2" border>
        <el-descriptions-item label="日志ID" :span="2">
          <el-tag type="info">{{ currentLog.id }}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="管理员">
          <div class="operator-info">
            <el-avatar :size="32" :src="currentLog.avatar" />
            <span>{{ currentLog.operator }}</span>
          </div>
        </el-descriptions-item>
        <el-descriptions-item label="操作类型">
          <el-tag
            :type="getOperationTypeTag(currentLog.operationType)"
            effect="dark"
          >
            {{ getOperationTypeLabel(currentLog.operationType) }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="操作模块">{{
          currentLog.module
        }}</el-descriptions-item>
        <el-descriptions-item label="IP地址">
          <el-link
            type="primary"
            :underline="false"
            @click="viewIpInfo(currentLog)"
          >
            {{ currentLog.ip }}
            <small v-if="currentLog.location"
              >({{ currentLog.location }})</small
            >
          </el-link>
        </el-descriptions-item>
        <el-descriptions-item label="操作时间">
          {{ formatDate(currentLog.operationTime, "YYYY-MM-DD HH:mm:ss") }}
        </el-descriptions-item>
        <el-descriptions-item label="操作状态">
          <el-tag
            :type="currentLog.status === 'success' ? 'success' : 'danger'"
            effect="dark"
          >
            {{ currentLog.status === "success" ? "成功" : "失败" }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="浏览器">{{
          currentLog.browser
        }}</el-descriptions-item>
        <el-descriptions-item label="操作描述" :span="2">
          {{ currentLog.description }}
        </el-descriptions-item>
        <el-descriptions-item label="请求URL" :span="2">
          <el-tag type="info">{{ currentLog.requestMethod }}</el-tag>
          {{ currentLog.requestUrl }}
        </el-descriptions-item>
        <el-descriptions-item label="请求参数" :span="2">
          <pre class="request-params">{{
            formatJson(currentLog.requestParams)
          }}</pre>
        </el-descriptions-item>
        <el-descriptions-item
          v-if="currentLog.status === 'fail'"
          label="错误信息"
          :span="2"
        >
          <pre class="error-message">{{ currentLog.errorMessage }}</pre>
        </el-descriptions-item>
      </el-descriptions>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="detailDialogVisible = false">关闭</el-button>
          <el-button type="primary" @click="exportCurrentLog">
            导出当前日志
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted, computed } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import {
  Document,
  Download,
  Refresh,
  Search,
  Delete,
  User,
  DataLine,
  SuccessFilled,
  Calendar,
  Warning,
} from "@element-plus/icons-vue";
import { formatDate } from "@/utils/date";
import request from "@/api/axios";
import * as XLSX from 'xlsx';

// 搜索表单
const searchForm = reactive({
  operator: "",
  operationType: "",
  status: "",
  dateRange: [],
});

// 认证头部
const authHeaders = computed(() => ({
  Authorization: `Bearer ${localStorage.getItem('token')}`
}));

// 日期快捷选项
const dateShortcuts = [
  {
    text: "最近一周",
    value: () => {
      const end = new Date();
      const start = new Date();
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
      return [start, end];
    },
  },
  {
    text: "最近一个月",
    value: () => {
      const end = new Date();
      const start = new Date();
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
      return [start, end];
    },
  },
  {
    text: "最近三个月",
    value: () => {
      const end = new Date();
      const start = new Date();
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
      return [start, end];
    },
  },
];

// 统计数据
const statistics = reactive({
  total: 0,
  success: 0,
  today: 0,
  error: 0,
});

// 表格数据
const loading = ref(false);
const logsList = ref([]);
const currentPage = ref(1);
const pageSize = ref(10);
const total = ref(0);

// 详情对话框
const detailDialogVisible = ref(false);
const currentLog = ref({});

// 测试数据
const mockLogs = [
  {
    id: "1001",
    operator: "管理员",
    avatar: "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png",
    operationType: "login",
    module: "系统",
    description: "管理员登录系统",
    ip: "192.168.1.1",
    location: "广西桂林",
    operationTime: "2024-03-15 10:30:00",
    status: "success",
    browser: "Chrome 121.0.0",
    requestUrl: "/api/admin/auth/login",
    requestMethod: "POST",
    requestParams: '{"username": "admin", "password": "******"}',
  },
  {
    id: "1002",
    operator: "超级管理员",
    avatar: "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png",
    operationType: "config",
    module: "系统设置",
    description: "修改系统支付配置",
    ip: "192.168.1.2",
    location: "广西桂林",
    operationTime: "2024-03-15 11:20:00",
    status: "success",
    browser: "Firefox 98.0.0",
    requestUrl: "/api/admin/settings/payment",
    requestMethod: "PUT",
    requestParams: '{"wxAppId": "wx123456", "wxMchId": "1234567890"}',
  },
  {
    id: "1003",
    operator: "运营员",
    avatar: "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png",
    operationType: "create",
    module: "商品管理",
    description: "新增商品信息",
    ip: "192.168.1.3",
    location: "广西桂林",
    operationTime: "2024-03-15 13:45:00",
    status: "success",
    browser: "Chrome 120.0.0",
    requestUrl: "/api/admin/products",
    requestMethod: "POST",
    requestParams: '{"name": "桂林特产", "price": 99.8}',
  },
  {
    id: "1004",
    operator: "审核员",
    avatar: "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png",
    operationType: "update",
    module: "内容审核",
    description: "审核用户评论",
    ip: "192.168.1.4",
    location: "广西桂林",
    operationTime: "2024-03-15 15:10:00",
    status: "success",
    browser: "Edge 100.0.0",
    requestUrl: "/api/admin/comments/1234/approve",
    requestMethod: "PUT",
    requestParams: '{"status": "approved", "remark": "通过审核"}',
  },
  {
    id: "1005",
    operator: "管理员",
    avatar: "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png",
    operationType: "delete",
    module: "用户管理",
    description: "删除违规用户",
    ip: "192.168.1.5",
    location: "广西桂林",
    operationTime: "2024-03-15 16:20:00",
    status: "fail",
    browser: "Chrome 121.0.0",
    requestUrl: "/api/admin/users/9876",
    requestMethod: "DELETE",
    requestParams: '{"reason": "违反平台规定"}',
    errorMessage: "数据库连接错误，请稍后重试"
  }
];

// 获取操作类型标签
const getOperationTypeLabel = (type) => {
  const types = {
    login: "登录",
    create: "新增",
    update: "修改",
    delete: "删除",
    export: "导出",
    config: "配置",
    other: "其他",
  };
  return types[type] || type;
};

// 获取操作类型标签样式
const getOperationTypeTag = (type) => {
  const types = {
    login: "info",
    create: "success",
    update: "warning",
    delete: "danger",
    export: "info",
    config: "primary",
    other: "",
  };
  return types[type] || "";
};

// 格式化 JSON
const formatJson = (json) => {
  try {
    return JSON.stringify(JSON.parse(json), null, 2);
  } catch (e) {
    return json;
  }
};

// 获取日志数据
const fetchLogs = async () => {
  loading.value = true;
  try {
    const params = {
      page: currentPage.value,
      size: pageSize.value,
      operator: searchForm.operator || undefined,
      operationType: searchForm.operationType || undefined,
      status: searchForm.status || undefined,
      startDate: searchForm.dateRange && searchForm.dateRange.length > 0 ? searchForm.dateRange[0] : undefined,
      endDate: searchForm.dateRange && searchForm.dateRange.length > 0 ? searchForm.dateRange[1] : undefined,
    };
    
    // 过滤掉undefined的参数
    Object.keys(params).forEach(key => params[key] === undefined && delete params[key]);
    
    const res = await request.get('/admin/logs', { 
      params,
      headers: authHeaders.value
    });
    
    if (res && res.data) {
      logsList.value = res.data.list || [];
      total.value = res.data.total || 0;
      
      // 更新统计数据
      if (res.data.statistics) {
        Object.assign(statistics, res.data.statistics);
      }
    } else {
      // 使用模拟数据
      logsList.value = mockLogs;
      total.value = mockLogs.length;
      
      // 模拟统计数据
      statistics.total = 1000;
      statistics.success = 950;
      statistics.today = 86;
      statistics.error = 50;
    }
  } catch (error) {
    console.error("获取日志数据失败:", error);
    ElMessage.warning("获取日志数据失败，显示本地数据");
    
    // 使用模拟数据
    logsList.value = mockLogs;
    total.value = mockLogs.length;
    
    // 模拟统计数据
    statistics.total = 1000;
    statistics.success = 950;
    statistics.today = 86;
    statistics.error = 50;
  } finally {
    loading.value = false;
  }
};

// 获取统计数据
const fetchStatistics = async () => {
  try {
    const res = await request.get('/admin/logs/statistics', {
      headers: authHeaders.value
    });
    
    if (res && res.data) {
      Object.assign(statistics, res.data);
    }
  } catch (error) {
    console.error("获取统计数据失败:", error);
    // 保持使用默认值
  }
};

// 搜索
const handleSearch = () => {
  currentPage.value = 1;
  fetchLogs();
};

// 重置搜索
const resetSearch = () => {
  searchForm.operator = "";
  searchForm.operationType = "";
  searchForm.status = "";
  searchForm.dateRange = [];
  handleSearch();
};

// 刷新日志
const refreshLogs = () => {
  fetchLogs();
  fetchStatistics();
};

// 查看详情
const viewDetail = (row) => {
  currentLog.value = row;
  detailDialogVisible.value = true;
};

// 查看IP信息
const viewIpInfo = (log) => {
  try {
    request.get(`/admin/logs/ip-info/${log.ip}`, {
      headers: authHeaders.value
    }).then(res => {
      if (res && res.data) {
        ElMessage.info(`IP地址: ${log.ip}, 位置: ${res.data.location || '未知'}, ISP: ${res.data.isp || '未知'}`);
      } else {
        ElMessage.info(`IP地址: ${log.ip}${log.location ? ` (${log.location})` : ""}`);
      }
    }).catch(() => {
      ElMessage.info(`IP地址: ${log.ip}${log.location ? ` (${log.location})` : ""}`);
    });
  } catch (error) {
    ElMessage.info(`IP地址: ${log.ip}${log.location ? ` (${log.location})` : ""}`);
  }
};

// 导出当前行日志
const exportCurrentLog = () => {
  try {
    // 创建工作簿
    const wb = XLSX.utils.book_new();
    
    // 准备数据
    const log = currentLog.value;
    const data = [
      ['字段', '内容'],
      ['日志ID', log.id],
      ['管理员', log.operator],
      ['操作类型', getOperationTypeLabel(log.operationType)],
      ['操作模块', log.module],
      ['操作描述', log.description],
      ['IP地址', log.ip],
      ['地理位置', log.location || '未知'],
      ['操作时间', formatDate(log.operationTime, "YYYY-MM-DD HH:mm:ss")],
      ['操作状态', log.status === 'success' ? '成功' : '失败'],
      ['浏览器', log.browser],
      ['请求URL', `${log.requestMethod} ${log.requestUrl}`],
      ['请求参数', log.requestParams]
    ];
    
    // 如果有错误信息，添加到数据中
    if (log.status === 'fail' && log.errorMessage) {
      data.push(['错误信息', log.errorMessage]);
    }
    
    // 创建工作表
    const ws = XLSX.utils.aoa_to_sheet(data);
    
    // 添加到工作簿
    XLSX.utils.book_append_sheet(wb, ws, '日志详情');
    
    // 导出文件
    XLSX.writeFile(wb, `管理员日志_${log.id}_${formatDate(new Date(), "YYYYMMDDHHmmss")}.xlsx`);
    
    ElMessage.success("日志导出成功");
  } catch (error) {
    console.error("导出日志失败:", error);
    ElMessage.error("导出日志失败，请重试");
  }
};

// 导出所有日志
const exportLogs = async () => {
  ElMessageBox.confirm("确定要导出所有管理员操作日志数据吗？", "导出确认", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(async () => {
    try {
      // 尝试从后端获取导出数据
      try {
        const res = await request.get('/admin/logs/export', {
          params: {
            operator: searchForm.operator || undefined,
            operationType: searchForm.operationType || undefined,
            status: searchForm.status || undefined,
            startDate: searchForm.dateRange && searchForm.dateRange.length > 0 ? searchForm.dateRange[0] : undefined,
            endDate: searchForm.dateRange && searchForm.dateRange.length > 0 ? searchForm.dateRange[1] : undefined,
          },
          responseType: 'blob',
          headers: authHeaders.value
        });
        
        const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' });
        const link = document.createElement('a');
        link.href = URL.createObjectURL(blob);
        link.download = '管理员操作日志_' + formatDate(new Date(), "YYYYMMDDHHmmss") + '.xlsx';
        link.click();
        
        ElMessage.success("日志导出成功");
        return;
      } catch (error) {
        console.error("从后端导出日志失败:", error);
        // 如果后端导出失败，继续使用前端导出
      }
      
      // 获取所有日志数据（如果有分页，需要获取所有页）
      let allLogs;
      try {
        const params = {
          page: 1,
          size: 1000, // 尝试一次获取更多数据
          operator: searchForm.operator || undefined,
          operationType: searchForm.operationType || undefined,
          status: searchForm.status || undefined,
          startDate: searchForm.dateRange && searchForm.dateRange.length > 0 ? searchForm.dateRange[0] : undefined,
          endDate: searchForm.dateRange && searchForm.dateRange.length > 0 ? searchForm.dateRange[1] : undefined,
        };
        
        const res = await request.get('/admin/logs', { 
          params,
          headers: authHeaders.value 
        });
        
        if (res && res.data && res.data.list) {
          allLogs = res.data.list;
        } else {
          // 使用当前页数据或模拟数据
          allLogs = logsList.value.length > 0 ? logsList.value : mockLogs;
        }
      } catch (error) {
        console.error("获取所有日志数据失败:", error);
        // 使用当前页数据或模拟数据
        allLogs = logsList.value.length > 0 ? logsList.value : mockLogs;
      }
      
      // 创建工作簿
      const wb = XLSX.utils.book_new();
      
      // 准备表头
      const headers = [
        '日志ID', '管理员', '操作类型', '操作模块', '操作描述', 
        'IP地址', '地理位置', '操作时间', '状态', '浏览器'
      ];
      
      // 准备数据
      const data = allLogs.map(log => [
        log.id,
        log.operator,
        getOperationTypeLabel(log.operationType),
        log.module,
        log.description,
        log.ip,
        log.location || '未知',
        formatDate(log.operationTime, "YYYY-MM-DD HH:mm:ss"),
        log.status === 'success' ? '成功' : '失败',
        log.browser
      ]);
      
      // 添加表头
      data.unshift(headers);
      
      // 创建工作表
      const ws = XLSX.utils.aoa_to_sheet(data);
      
      // 设置列宽
      const wscols = [
        { wch: 10 }, // 日志ID
        { wch: 12 }, // 管理员
        { wch: 10 }, // 操作类型
        { wch: 12 }, // 操作模块
        { wch: 40 }, // 操作描述
        { wch: 15 }, // IP地址
        { wch: 20 }, // 地理位置
        { wch: 20 }, // 操作时间
        { wch: 8 },  // 状态
        { wch: 15 }  // 浏览器
      ];
      ws['!cols'] = wscols;
      
      // 添加到工作簿
      XLSX.utils.book_append_sheet(wb, ws, '管理员日志');
      
      // 导出文件
      XLSX.writeFile(wb, '管理员操作日志_' + formatDate(new Date(), "YYYYMMDDHHmmss") + '.xlsx');
      
      ElMessage.success("管理员操作日志导出成功");
    } catch (error) {
      console.error("导出日志失败:", error);
      ElMessage.error("导出日志失败，请重试");
    }
  }).catch(() => {});
};

// 分页相关方法
const handleSizeChange = (val) => {
  pageSize.value = val;
  fetchLogs();
};

const handleCurrentChange = (val) => {
  currentPage.value = val;
  fetchLogs();
};

// 页面加载时获取数据
onMounted(() => {
  fetchLogs();
  fetchStatistics();
});
</script>

<style scoped>
.system-logs {
  padding: 20px;
}

.main-card {
  background-color: var(--el-bg-color);
  border-radius: 8px;
  box-shadow: var(--el-box-shadow-light);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-icon {
  font-size: 20px;
  color: var(--el-color-primary);
}

.header-title {
  font-size: 16px;
  font-weight: 600;
}

.header-right {
  display: flex;
  gap: 12px;
}

.search-form {
  margin: 20px 0;
  padding: 20px;
  background-color: var(--el-fill-color-light);
  border-radius: 4px;
}

.statistics-panel {
  margin-bottom: 20px;
}

.statistics-card {
  height: 120px;
  transition: all 0.3s ease;
}

.statistics-card:hover {
  transform: translateY(-5px);
}

.statistics-card.success :deep(.el-card__header) {
  background-color: var(--el-color-success-light-9);
}

.statistics-card.warning :deep(.el-card__header) {
  background-color: var(--el-color-warning-light-9);
}

.statistics-card.danger :deep(.el-card__header) {
  background-color: var(--el-color-danger-light-9);
}

.statistics-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: var(--el-text-color-regular);
}

.statistics-icon {
  font-size: 20px;
  color: var(--el-color-primary);
}

.statistics-value {
  font-size: 24px;
  font-weight: bold;
  color: var(--el-text-color-primary);
  text-align: center;
  margin-top: 10px;
}

.operator-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.time-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.time-detail {
  font-size: 12px;
  color: var(--el-text-color-secondary);
}

.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

.empty-state {
  padding: 40px 0;
}

.empty-text {
  font-size: 16px;
  color: var(--el-text-color-secondary);
  margin-top: 10px;
}

.empty-subtext {
  font-size: 14px;
  color: var(--el-text-color-placeholder);
  margin-top: 5px;
}

.mt-4 {
  margin-top: 16px;
}

.operator-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.request-params {
  margin: 0;
  padding: 8px;
  background-color: var(--el-fill-color-light);
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 200px;
  overflow-y: auto;
}

.error-message {
  margin: 0;
  padding: 8px;
  background-color: var(--el-color-danger-light-9);
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
  color: var(--el-color-danger);
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 200px;
  overflow-y: auto;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

:deep(.el-dialog__body) {
  padding: 20px;
}
</style>
